package sort.quick;

public class sortArray1 {
    public int[] sortArray(int[] nums) {
        quickSort(nums,0,nums.length-1);
        return nums;
    }
    public void quickSort(int[] nums,int start,int end) {
        if(start < end) {
            int key = nums[start];
            int left = start;
            int right = end;
            while(left < right){
                //从右往左找比key小的数
                while(left < right&&nums[right] > key){
                    right--;
                }
                nums[left] = nums[right];
                //从左往右找比key大的数
                while(left < right && nums[left] <= key ) {
                    left++;
                }
                nums[right] = nums[left];
            }
            nums[left] = key;
            quickSort(nums,start,left-1);
            quickSort(nums,left+1,end);
        }
    }
}
